//
//  LFMarketViewCell.m
//  LoveFruit
//
//  Created by Apple on 16/9/24.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFMarketViewCell.h"
#import "FLlabel.h"
//int num = 0;
@interface LFMarketViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *marketImage;
@property (weak, nonatomic) IBOutlet UIImageView *titleImage;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *sendLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceNewLabel;
@property (weak, nonatomic) IBOutlet FLlabel *priceOldLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UIButton *addNumberButton;
@property (weak, nonatomic) IBOutlet UIButton *jianNumberButton;
@end



@implementation LFMarketViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
}
- (IBAction)addNumber:(id)sender {
    
    self.jianNumberButton.hidden = NO;
    self.numberLabel.hidden = NO;
    self.rightModel.ismix++;

    if (self.rightModel.ismix > self.rightModel.number) {
        [SVProgressHUD showInfoWithStatus:@"库存不够"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        self.rightModel.ismix--;
    }
    else{
         UIImage *image = self.marketImage.image;
       // CGPoint start = [self.marketImage convertPoint:self.marketImage.center toView:self.window];
        //NSLog(@"%zd",start);
        //UIImageView *imageview = self.marketImage.copy;
        if ([self.delegate respondsToSelector:@selector(getWith:andIndexpath:andImage:)]) {
            [self.delegate getWith:self andIndexpath:self.marketImage andImage:image];
        }
    }
    self.numberLabel.text = @(self.rightModel.ismix).description;
    
}
- (IBAction)jianNumber:(id)sender {
    if (self.rightModel.ismix > 1) {
        self.rightModel.ismix--;
        self.numberLabel.text = @(self.rightModel.ismix).description;
    }
    else if(self.rightModel.ismix == 1){
        self.jianNumberButton.hidden = YES;
        self.numberLabel.hidden = YES;
        self.rightModel.ismix = 0;
    }
    if ([self.delegate respondsToSelector:@selector(getWith:andIndexpath:andImage:)]) {
        [self.delegate getWith:self andIndexpath:self.marketImage andImage:nil];
    }

}
-(void)setRightModel:(LFHotSellerModel *)rightModel{
    _rightModel = rightModel;
    [self.marketImage sd_setImageWithURL:[NSURL URLWithString:rightModel.img] placeholderImage:nil];
    self.title.text = self.rightModel.name;
    if (self.rightModel.is_xf) {
        self.titleImage.hidden = NO;
        [self.titleImage mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.offset(35);
        }];
    }
    else{
        self.titleImage.hidden = YES;
        [self.titleImage mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.offset(0);
        }];

    }
    self.titleImage.hidden = self.rightModel.is_xf == 1 ? NO : YES;
    self.sendLabel.layer.cornerRadius = 5;
    self.sendLabel.layer.masksToBounds = YES;
    if (![self.rightModel.pm_desc isEqualToString:@""]) {
        self.sendLabel.hidden = NO;
        self.sendLabel.text = [NSString stringWithFormat:@" %@ ",self.rightModel.pm_desc];
    }
    else{
        self.sendLabel.hidden = YES;
    }
    //    self.sendIamge.hidden = self.rightModel.pm_desc == nil ? YES : NO;
    self.priceLabel.text = self.rightModel.specifics;
    self.priceNewLabel.text = [NSString stringWithFormat:@"$%@",self.rightModel.price];
    self.priceOldLabel.text = [NSString stringWithFormat:@"$%@",self.rightModel.market_price];
    if (self.rightModel.ismix != 0) {
        self.jianNumberButton.hidden = NO;
        self.numberLabel.hidden = NO;
        self.numberLabel.text = @(self.rightModel.ismix).description;
    }else{
        self.jianNumberButton.hidden = YES;
        self.numberLabel.hidden = YES;
        
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    
}

@end
